home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Development / General / MM3Tp.sea Folder / Made by Marksman / Sources / mm / mmMenuMM_Demo.p < prev    next >
Text File  |  1994-01-16  |  10KB  |  343 lines

  1. Unit mmMenuMM_Demo;
  2. {  Copyright © 1994 George R. Cossey }
  3. {  mmMenuMM_Demo                Handle menus
  4.  
  5.     File name:  mmMenuMM_Demo
  6.     Function:  This contains the routines to handle menus.
  7.     History: 1/16/94 Original by George Cossey
  8.  
  9.    }
  10.  
  11.  
  12. interface
  13.  
  14.     uses
  15.         Printing,Folders,Sound,mmCommonMM_Demo,CommonMM_Demo,
  16.         UeventsMM_Demo,{}
  17.         mmPA_My_Alert,
  18.         {}
  19.         mmD_My_Modal,
  20.         {}
  21.         mmMD_My_Movable_Moda,
  22.         mmMD_My_Modeless,
  23.         mmMD_About_Demo,
  24.         {}
  25.         mmW_My_basic_window,
  26.         mmW_Floating_window,
  27.         {}
  28.         UmenuMM_Demo;
  29.  
  30. procedure Init_My_Menus;
  31. procedure Handle_My_Menu(theMenu,theItem:integer);
  32.  
  33. {NOTE: This routine is in this file to allow access to it by routines in the Common file}
  34. { If this routine were in Main then it would not link properly}
  35. procedure DoActivate;
  36.  
  37. { ======================================================= }
  38. { ======================================================= }
  39.  
  40. implementation
  41.  
  42. { ======================================================= }
  43. { ======================================================= }
  44.  
  45. { Routine: DoActivate }
  46. { Purpose: Got an activate or deactivate event }
  47.  
  48. procedure DoActivate;
  49. var
  50.     whichWindow:WindowPtr;                        { See which window for event }
  51.     Do_An_Activate:Boolean;                        { Flag to pass }
  52.     theRefCon:longint;                            { Refcon with layer masked off }
  53.  
  54.  
  55. begin
  56. whichWindow := WindowPtr(myEvent.message);        { Get the window the update is for }
  57.  
  58. Do_An_Activate := (BAND(myEvent.modifiers,$0001) <> 0);{ Make sure it is Activate and not DeActivate }
  59. theRefCon := GetWRefCon(whichWindow);            { Get the refcon }
  60. theRefCon := BAND(theRefCon,$00FFFFFF);                { Mask the layer out }
  61. case (theRefCon) of                                { Do the appropiate window }
  62.     -1:begin end;
  63.     ResW_My_basic_window:
  64.         Activate_My_basic_window(whichWindow,Do_An_Activate);    { Activate or deactivate this window }
  65.     ResW_Floating_window:
  66.         Activate_Floating_window(whichWindow,Do_An_Activate);    { Activate or deactivate this window }
  67.  
  68.     otherwise                                    { allow other buttons, trap for debug }
  69.         U_Activate(whichWindow,Do_An_Activate);    { Allow user to handle others }
  70.     end;                                            { end of switch }
  71. end;
  72.  
  73. { ======================================================= }
  74.  
  75. { Routine: Init_My_Menus }
  76. { Purpose: Load in the menu lists and initialize the menubar }
  77.  
  78. procedure Init_My_Menus;
  79.  
  80.  
  81. begin
  82. ClearMenuBar;                                        { Clear any old menu bars }
  83.  
  84. { This menu is   }
  85. Menu_Apple := GetMenu(Res_Menu_Apple);    { Get the menu from the resource file }
  86. InsertMenu(Menu_Apple,0);                        { Insert this menu into the menu bar }
  87. AddResMenu(Menu_Apple,'DRVR');                { Add in DAs }
  88.  
  89. { This menu is  File }
  90. Menu_File := GetMenu(Res_Menu_File);    { Get the menu from the resource file }
  91. InsertMenu(Menu_File,0);                        { Insert this menu into the menu bar }
  92.  
  93. { This menu is  Edit }
  94. Menu_Edit := GetMenu(Res_Menu_Edit);    { Get the menu from the resource file }
  95. InsertMenu(Menu_Edit,0);                        { Insert this menu into the menu bar }
  96.  
  97. { This menu is  Windows }
  98. Menu_Windows := GetMenu(Res_Menu_Windows);    { Get the menu from the resource file }
  99. InsertMenu(Menu_Windows,0);                        { Insert this menu into the menu bar }
  100.  
  101. AddExtraMenus;                                        { Add any extra menu lists }
  102.  
  103. DrawMenuBar;                                        { Draw the menu bar }
  104. end;
  105.  
  106. { ======================================================= }
  107.  
  108. { Routine: DoMenuApple }
  109. { Purpose: Handle all menu items in this list }
  110.  
  111. procedure DoMenuApple(theItem: integer);
  112. var
  113.     SkipProcessing:Boolean;                        { TRUE says skip processing }
  114.     DNA:integer;                                { For opening DAs }
  115.     DAName:Str255;                                { For getting DA name }
  116.     SavePort:GrafPtr;                            { Save current port when opening DAs }
  117.  
  118.  
  119. begin
  120. SkipProcessing := false;                            { Set to not skip the processing of this menu item }
  121.  
  122. Do_AppleMenu(true,theItem,SkipProcessing);    { Pre menu handler  }
  123.  
  124. if (not(SkipProcessing)) then                    { See if process the menu list }
  125.     begin
  126.     case (theItem) of                        { Handle all commands in this menu list }
  127.         -1:begin end;
  128.         MItem_About_Demo:                    { For item About Demo… }
  129.             begin
  130.         Add_UserEvent(UserEvent_Open_Window,ResD_About_Demo,0,0,nil);    { Open this modeless dialog }
  131.             end;
  132.         otherwise                                { allow other buttons, trap for debug }
  133.             begin
  134.             GetPort(SavePort);                    { Save the current port }
  135.             GetItem(Menu_Apple,theItem,DAName);    { Get the name of the DA selected }
  136.             DNA := OpenDeskAcc(DAName);            {Open the DA selected }
  137.             SetPort(SavePort);                    { Restore to the saved port }
  138.             end;                                { end of otherwise }
  139.         end;                                        { end of switch }
  140.     end;
  141.  
  142. Do_AppleMenu(false,theItem,SkipProcessing);    { Post menu handler  }
  143. end;
  144.  
  145. { ======================================================= }
  146.  
  147. { Routine: DoMenuFile }
  148. { Purpose: Handle all menu items in this list }
  149.  
  150. procedure DoMenuFile(theItem: integer);
  151. var
  152.     SkipProcessing:Boolean;                        { TRUE says skip processing }
  153.  
  154.  
  155. begin
  156. SkipProcessing := false;                            { Set to not skip the processing of this menu item }
  157.  
  158. Do_FileMenu(true,theItem,SkipProcessing);    { Pre menu handler  }
  159.  
  160. if (not(SkipProcessing)) then                    { See if process the menu list }
  161.     begin
  162.     case (theItem) of                        { Handle all commands in this menu list }
  163.         -1:begin end;
  164.         MItem_New:                    { For item New }
  165.             begin
  166.             end;
  167.         MItem_Open:                    { For item Open… }
  168.             begin
  169.         Open_The_File;                { Do file open }
  170.             end;
  171.         MItem_Close:                    { For item Close }
  172.             begin
  173.             end;
  174.         MItem_Save:                    { For item Save }
  175.             begin
  176.         Save_The_File;                { Do file save }
  177.             end;
  178.         MItem_Save_As:                    { For item Save As… }
  179.             begin
  180.         Save_The_File;                { Do file save }
  181.             end;
  182.         MItem_Revert:                    { For item Revert }
  183.             begin
  184.             end;
  185.         MItem_Page_Setup:                    { For item Page Setup… }
  186.             begin
  187.         PageSetup;                    { Do Printing PageSetup }
  188.             end;
  189.         MItem_Print:                    { For item Print… }
  190.             begin
  191.         Print_The_Data;                { Do Printing }
  192.             end;
  193.         MItem_Quit:                    { For item Quit }
  194.             begin
  195.             doneFlag := true;                    { Quit }
  196.             end;
  197.         otherwise                                { allow other buttons, trap for debug }
  198.             begin
  199.             end;                                { end of otherwise }
  200.         end;                                        { end of switch }
  201.     end;
  202.  
  203. Do_FileMenu(false,theItem,SkipProcessing);    { Post menu handler  }
  204. end;
  205.  
  206. { ======================================================= }
  207.  
  208. { Routine: DoMenuEdit }
  209. { Purpose: Handle all menu items in this list }
  210.  
  211. procedure DoMenuEdit(theItem: integer);
  212. var
  213.     SkipProcessing:Boolean;                        { TRUE says skip processing }
  214.     BoolHolder:Boolean;                            { For SystemEdit result }
  215.  
  216.  
  217. begin
  218. SkipProcessing := false;                            { Set to not skip the processing of this menu item }
  219.  
  220. Do_EditMenu(true,theItem,SkipProcessing);    { Pre menu handler  }
  221.  
  222. if (not(SkipProcessing)) then                    { See if process the menu list }
  223.     begin
  224.    BoolHolder := SystemEdit(theItem - 1);        { Let the DA do the edit to itself }
  225.  
  226.     if (not(BoolHolder)) then                    { If not a DA then we get it }
  227.     begin
  228.  
  229.     case (theItem) of                        { Handle all commands in this menu list }
  230.         -1:begin end;
  231.         MItem_Undo:                    { For item Undo }
  232.             begin
  233.             end;
  234.         MItem_Cut:                    { For item Cut }
  235.             begin
  236.             end;
  237.         MItem_Copy:                    { For item Copy }
  238.             begin
  239.             end;
  240.         MItem_Paste:                    { For item Paste }
  241.             begin
  242.             end;
  243.         MItem_Clear:                    { For item Clear }
  244.             begin
  245.             end;
  246.         MItem_Select_All:                    { For item Select All }
  247.             begin
  248.             end;
  249.         otherwise                                { allow other buttons, trap for debug }
  250.             begin
  251.             end;                                { end of otherwise }
  252.         end;                                        { end of switch }
  253.     end;
  254.     end;
  255.  
  256. Do_EditMenu(false,theItem,SkipProcessing);    { Post menu handler  }
  257. end;
  258.  
  259. { ======================================================= }
  260.  
  261. { Routine: DoMenuWindows }
  262. { Purpose: Handle all menu items in this list }
  263.  
  264. procedure DoMenuWindows(theItem: integer);
  265. var
  266.     SkipProcessing:Boolean;                        { TRUE says skip processing }
  267.  
  268.  
  269. begin
  270. SkipProcessing := false;                            { Set to not skip the processing of this menu item }
  271.  
  272. Do_WindowsMenu(true,theItem,SkipProcessing);    { Pre menu handler  }
  273.  
  274. if (not(SkipProcessing)) then                    { See if process the menu list }
  275.     begin
  276.     case (theItem) of                        { Handle all commands in this menu list }
  277.         -1:begin end;
  278.         MItem_Alert:                    { For item Alert… }
  279.             begin
  280.         PA_My_Alert;            { Open this alert }
  281.             end;
  282.         MItem_Modal_Dialog:                    { For item Modal Dialog… }
  283.             begin
  284.         MPD_My_Modal;            { Open this modal dialog }
  285.             end;
  286.         MItem_Movable_Modal_D:                    { For item Movable Modal Dialog… }
  287.             begin
  288.         Add_UserEvent(UserEvent_Open_Window,ResD_My_Movable_Moda,0,0,nil);    { Open this modeless dialog }
  289.             end;
  290.         MItem_Modeless_Dialog:                    { For item Modeless Dialog… }
  291.             begin
  292.         Add_UserEvent(UserEvent_Open_Window,ResD_My_Modeless,0,0,nil);    { Open this modeless dialog }
  293.             end;
  294.         MItem_Window:                    { For item Window… }
  295.             begin
  296.         Add_UserEvent(UserEvent_Open_Window,ResW_My_basic_window,0,0,nil);    { Open this window }
  297.             end;
  298.         MItem_Floating_window:                    { For item Floating window… }
  299.             begin
  300.         Add_UserEvent(UserEvent_Open_Window,ResW_Floating_window,0,0,nil);    { Open this window }
  301.             end;
  302.         otherwise                                { allow other buttons, trap for debug }
  303.             begin
  304.             end;                                { end of otherwise }
  305.         end;                                        { end of switch }
  306.     end;
  307.  
  308. Do_WindowsMenu(false,theItem,SkipProcessing);    { Post menu handler  }
  309. end;
  310.  
  311. { ======================================================= }
  312.  
  313. { ======================================================= }
  314.  
  315. { Routine: Handle_My_Menu }
  316. { Purpose: Vector off to the appropiate menu list handler }
  317.  
  318. procedure Handle_My_Menu(theMenu,theItem:integer);
  319.  
  320.  
  321. begin
  322. case (theMenu) of                                { Do selected menu list }
  323.     -1:begin end;
  324.     Res_Menu_Apple:
  325.         DoMenuApple(theItem);                    { Go handle this list,  }
  326.     Res_Menu_File:
  327.         DoMenuFile(theItem);                    { Go handle this list, File }
  328.     Res_Menu_Edit:
  329.         DoMenuEdit(theItem);                    { Go handle this list, Edit }
  330.     Res_Menu_Windows:
  331.         DoMenuWindows(theItem);                    { Go handle this list, Windows }
  332.  
  333.     otherwise                                        { allow other buttons, trap for debug }
  334.         Handle_Other_Menus(theMenu,theItem);        { Handle other special menus }
  335.     end;                                                { end of switch }
  336.  
  337. HiliteMenu(0);                                        { Turn menu selection off }
  338. end;
  339.  
  340. { ======================================================= }
  341. { ======================================================= }
  342. end.
  343.